/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MyClass;

import java.util.Random;
import java.util.Vector;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

/**
 *
 * @author HuuTai_it
 */
public class EnemyManagement {
    
    private GameManagement gameMng;
    private long time = System.currentTimeMillis();
    private Image blackShip = Image.createImage("/MyPicture/blackship.png");
    private Image redShip = Image.createImage("/MyPicture/redship.png");
    private Image blueShip = Image.createImage("/MyPicture/blueship.png");
    private Image ghostShip = Image.createImage("/MyPicture/ghostship.png");
    private Image monster = Image.createImage("/MyPicture/monster.png");
    public Vector vEnemy = new Vector();
    
    public EnemyManagement(GameManagement gameMng) throws Exception {
        
        //lay diff de random so enemy moi loai cho thik hop
        
        this.gameMng = gameMng;
        Random r = new Random();
        int numBlackShip = 0;
        int numRedShip = 0;
        int numBlueShip = 0;
        int numGhostShip = 0;
        int numMonster = 0;
        
        int lv = gameMng.control.level;
        int diff = gameMng.control.difficulties;

        numBlackShip = Math.abs(r.nextInt() % 4) + 2 + lv / 6 + (diff -  Math.abs(r.nextInt() % diff));
        numRedShip = Math.abs((lv / 6) * (diff -  Math.abs(r.nextInt() % diff)) - diff / 3);
        numBlueShip = Math.abs((lv / 6) * (diff -  Math.abs(r.nextInt() % diff)) - diff / 3);
        numBlueShip = Math.abs((lv / 6) * (diff -  Math.abs(r.nextInt() % diff)) - diff / 3);
        numMonster = Math.abs(r.nextInt() % 2) * (lv / 6) * (diff -  Math.abs(r.nextInt() % diff)); 
        
        
        for(int i = 0; i < numBlackShip; i++) {    
                
            Ship s = new BlackShip(gameMng, blackShip);
            vEnemy.addElement(s);
        }
        
        for(int i = 0; i < numRedShip; i++) {     
                
            Ship s = new RedShip(gameMng, redShip);
            vEnemy.addElement(s); 
        }
        
        for(int i = 0; i < numBlueShip; i++) {
                
            Ship s = new BlueShip(gameMng, blueShip);
            vEnemy.addElement(s);
        }
        
        for(int i = 0; i < numGhostShip; i++) {
                
            Ship s = new GhostShip(gameMng, ghostShip);
            vEnemy.addElement(s);
        }
        
        for(int i = 0; i < numMonster; i++) {
                
            Ship s = new Monster(gameMng, monster);
            vEnemy.addElement(s);
        }
    }
    
    public void wobble(long currTime) {
            
        int n = vEnemy.size();
        if(currTime - time > 150)
        {
            for(int i = 0; i < n; i++)
                ((Sprite)vEnemy.elementAt(i)).nextFrame();
            
            time = currTime;
        }
    }
}
